package com.eendtech.www.cqcet_eschool;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

/**
 * Created by Seale [QQ:1801157108] on 2018/4/26.
 * Tools:工具类 EditTextClear
 */

public class EditTextClearTools {

    public static void addclerListenner(final EditText e1, final ImageView m1){
        e1.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                // 监听如果输入串长度大于0那么就显示clear按钮。
                String s1 = s.toString();
                if (s.length() > 0){
                    m1.setVisibility(View.VISIBLE);
                }else {
                    m1.setVisibility(View.INVISIBLE);
                }


            }
        });

        m1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                e1.setText("");
            }
        });


    }



}
